///////////////////////////////////////////////////////////
//  SaveTemplateCommand.cpp
//  Implementation of the Class SaveTemplateCommand
//  Created on:      21-Sep-2013 12:08:40 PM
//  Original author: Jakkaphan Aiemcharoenjit
///////////////////////////////////////////////////////////

#include "SaveTemplateCommand.h"
#include "CurrentCommand.h"
#include "DataManager.h"

using namespace UI;
using namespace UI::CMD;


SaveTemplateCommand::SaveTemplateCommand(CCreateTemplateView* createTemplate, CTemplateView* _template, CSaveView* saveView)
{
  this->m_type = ICommand::SAVETEMPLATE_CMD;
  this->m_createTemplateView = createTemplate;
  this->m_templateView = _template;
  this->m_saveView = saveView;
}


SaveTemplateCommand::~SaveTemplateCommand()
{

}


void SaveTemplateCommand::Execute()
{
  switch(CurrentCommand::GetInstance()->GetNewOrEditCommand())
  {
  case ICommand::EDITTEMPLATE_CMD:
    {
			IPage* editPage = this->m_createTemplateView->GetPage();
			editPage->UpdateTemplateTime();
      this->m_templateView->EditPage(editPage);
			this->m_templateView->Refresh();
    }
    break;
  case ICommand::NEWTEMPLATE_CMD:
    {
      IPage* newPage = this->m_createTemplateView->GetPage();
      newPage->SetName(this->m_saveView->GetNameLabel());
      newPage->SetTemplateName(this->m_saveView->GetNameLabel());
			newPage->UpdateTemplateTime();
      this->m_templateView->AppendPage(newPage);
      this->m_templateView->Refresh();
    }
    break;
  default: break;
  }
  // Set current command
  DataManager::GetInstance()->Save();
  CurrentCommand::GetInstance()->SetCurrentCommand(this->m_type);
  CurrentCommand::GetInstance()->SetNewOrEditCommand(ICommand::UNKNOWN_CMD);
}


ICommand::CommandType SaveTemplateCommand::GetType()
{
	return this->m_type;
}